package com.school.admin.controller;


import com.school.admin.common.annotation.DataAuthority;
import com.school.admin.common.result.R;
import com.school.admin.entity.vo.MallSysRoleVo;
import com.school.admin.service.MallMenuRoleService;
import com.school.admin.service.MallMenuService;
import com.school.admin.service.MallSysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 菜单角色中间表 前端控制器
 * </p>
 *
 * @author sunpx
 * @since 2022-03-24
 */
@RestController
@RequestMapping("/mall-menu-role")
@Api(tags = "菜单角色绑定")
public class MallMenuRoleController {

    @Autowired
    private MallMenuService mallMenuService;


    @Autowired
    private MallMenuRoleService mallMenuRoleService;


    @Autowired
    private MallSysRoleService mallSysRoleService;


    @GetMapping("getByModuleCode/{id}")
    @ApiOperation("返回编辑菜单时所需数据")
    public R getByModuleCode(@PathVariable String id) {

        return R.ok()
                .data("tree", mallMenuService.getMenuAll())
                .data("finallyList", mallMenuRoleService.getFinallyModule(id))
                .data("role", mallSysRoleService.getById(id));
    }


    @PostMapping("save")
    @ApiOperation("保存/为角色赋予权限")
    @DataAuthority(name = "角色授权菜单", key = 7)
    public R save(@RequestBody MallSysRoleVo commonSave) {
        return R.th(mallMenuRoleService.saveMenuRoleService(commonSave));
    }


    @GetMapping("getById/{id}")
    @ApiOperation("查询菜单详情")
    public R getBy(@PathVariable String id) {
        return R.ok().data("data", mallMenuService.getByModel(id));
    }

}

